package zoran.wang.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * description：
 *
 * @author wangzhuo
 * @date 2022/3/18 21:20
 * @Email zoranwang@yeah.net
 */
public class MyBeanPostProcessor implements BeanPostProcessor {

    /**
     * 初始化方法，Bean对象创建之后马上调用
     *
     * @param bean     当前的初始化对象实例
     * @param beanName 当前初始化对象的id值
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

        System.out.println("后置处理器器初始化..." + "," + bean + "," + beanName);

        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    /**
     * 销毁方法，spring容器销毁时，bean对象被销毁之前调用
     *
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        System.out.println("后置处理器销毁..." + "," + bean + "," + beanName);

        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}
